package br.com.condominio.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@SequenceGenerator(name = "responsavel_resp_codigo_seq", sequenceName = "responsavel_resp_codigo_seq", allocationSize = 1)
public class Responsavel implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private Integer respCodigo;
	private Funcao funcao;
	private Pessoa pessoa;
	private Bloco bloco;
	private Date respInicio;
	private Date respFim;

	public Responsavel() {
	}

	public Responsavel(Integer respCodigo, Funcao funcao, Pessoa pessoa,
			Bloco bloco, Date respInicio) {
		this.respCodigo = respCodigo;
		this.funcao = funcao;
		this.pessoa = pessoa;
		this.bloco = bloco;
		this.respInicio = respInicio;
	}

	public Responsavel(Integer respCodigo, Funcao funcao, Pessoa pessoa,
			Bloco bloco, Date respInicio, Date respFim) {
		this.respCodigo = respCodigo;
		this.funcao = funcao;
		this.pessoa = pessoa;
		this.bloco = bloco;
		this.respInicio = respInicio;
		this.respFim = respFim;
	}

	@Id
	@Column(name = "resp_codigo", unique = true, nullable = false, precision = 131089, scale = 0)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "responsavel_resp_codigo_seq")

	public Integer getRespCodigo() {
		return this.respCodigo;
	}

	public void setRespCodigo(Integer respCodigo) {
		this.respCodigo = respCodigo;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "func_codigo", nullable = false)
	public Funcao getFuncao() {
		if (this.funcao == null)
			this.funcao = new Funcao();
		return this.funcao;
	}

	public void setFuncao(Funcao funcao) {
		this.funcao = funcao;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "pesso_codigo", nullable = false)
	public Pessoa getPessoa() {
		if(this.pessoa == null)
			this.pessoa = new Pessoa();
		return this.pessoa;
	}

	public void setPessoa(Pessoa pessoa) {
		this.pessoa = pessoa;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "blo_codigo", nullable = false)
	public Bloco getBloco() {
		if(this.bloco == null)
			this.bloco = new Bloco();
		return this.bloco;
	}

	public void setBloco(Bloco bloco) {
		this.bloco = bloco;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "resp_inicio", nullable = false, length = 29)
	public Date getRespInicio() {
		return this.respInicio;
	}

	public void setRespInicio(Date respInicio) {
		this.respInicio = respInicio;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "resp_fim", length = 29)
	public Date getRespFim() {
		return this.respFim;
	}

	public void setRespFim(Date respFim) {
		this.respFim = respFim;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((respCodigo == null) ? 0 : respCodigo.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Responsavel other = (Responsavel) obj;
		if (respCodigo == null) {
			if (other.respCodigo != null)
				return false;
		} else if (!respCodigo.equals(other.respCodigo))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Responsavel [respCodigo=" + respCodigo + ", funcao=" + funcao
				+ ", pessoa=" + pessoa + ", bloco=" + bloco + ", respInicio="
				+ respInicio + ", respFim=" + respFim + "]";
	}
	
	

}
